package com.mi.million.common.util;

import com.mi.rule.util.project.MiException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.validation.BindingResult;

import java.util.Set;
import java.util.stream.Collectors;

public interface BaseController {
    //检查参数
    default void checkParam(BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            Set<String> collect = bindingResult.getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.toSet());
            throw new MiException(String.join(",", collect));
        }
    }
}
